/**
 * 处理登录页面的事务
 */
var d1 = require("deviceone");
var do_Global = d1.sm("do_Global");
var dojs = require("dojs");
var dataCache = d1.sm("do_DataCache");
var do_Network = d1.sm("do_Network");

module.exports.edtFocusEvent  = function(edt,line){
	
	edt.on("focusIn",function(){
		line.bgColor = do_Global.getMemory("edt_focus_in_line_color");
	});
	edt.on("focusOut",function(){
		line.bgColor = do_Global.getMemory("edt_focus_out_line_color");
	});
};

//提交信息
module.exports.invoke = function(user,name){
	dojs.core.p(JSON.stringify(user));
	//判断是否有网络
	if (dojs.core.valueEqual(do_Network.getStatus(), "none")) {
		dojs.core.toast("请检查网络");
		return;
	}else{
		dojs.http.ajax({
			url : do_Global.getMemory("update_user_url"),
			type : "POST",
			data:user,
			success : function(data) {//返回值data本身就是json对象
				
				dojs.core.p(JSON.stringify(data));
				if (! data.success) {
					
					if (! dojs.core.isNullData(data.token)) {
						dojs.core.toast("会话已过期，请重新登陆");
						// 打开登录页面
						var entrance = require("source://script/mymodule/entrance");
						entrance.openLogin.openLoginPage();
						dojs.core.closePage();
						return;
					}
					dojs.core.p("用户信息更新失败，请稍后重试");
					return;
				}
				
				dojs.core.p("更新用户信息成功");
				//存储地址
				user.province = name.province;
				user.city = namec.city;
				dataCache.saveData(do_Global.getMemory("data_label").user_data, JSON.stringify(user));
				// 打开首页页面
				var entrance = require("source://script/mymodule/entrance");
				entrance.openHome.openHomePage();
				dojs.core.closePage();
				
			},
			error : function(data) {
				dojs.core.p("网络错误");
			}
		});
	}
}
